function s=V4_trapec(k,l,M,v)
N=length(v);
dkl(1:N)=0;
p(1:N)=0;
r(1:N)=0;
s(1:N)=0;
for i=1:1:N
    if(i-k-l>0) dkl(i)=v(i)-v(i-k)-v(i-l)+v(i-k-l);
    else if(i-k>0&&i-l>0) dkl(i)=v(i)-v(i-k)-v(i-l);
        else if(i-k>0) dkl(i)=v(i)-v(i-k);
            else if(i-l>0) dkl(i)=v(i)-v(i-l);
                else dkl(i)=v(i);
                end
            end
        end
    end
    if(i>1) p(i)=p(i-1)+dkl(i);
    else p(i)=dkl(i);
    end
    r(i)=p(i)+M*dkl(i);
    if(i>1) s(i)=s(i-1)+r(i);
    else s(i)=r(i);
    end
end
end
